package ch.sfug.controls {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;	

	/**
	 * @author loop
	 */
	public dynamic class InactiveButton extends MovieClip {

		private var isOver:Boolean;

		public function InactiveButton(  ) {

			addEventListener(MouseEvent.MOUSE_OVER, onOver);
			addEventListener(MouseEvent.MOUSE_DOWN, onDown);
			addEventListener(MouseEvent.MOUSE_OUT, onOut);

			buttonMode = true;
			mouseChildren = false;
			isOver = false;

			onOut();
		}

		
		protected function onOut( e:Event = null ):void {
			if( enabled ) this.gotoAndStop("up");
			isOver = false;
		}

		
		protected function onOver( e:Event = null ):void {
			this.gotoAndStop("over");
			isOver = true;
		}

		
		protected function onDown( e:Event ):void {
			this.gotoAndStop("down");
		}

		
		/**
		 * overrides the super function to adjust the state
		 */
		public override function set enabled( b:Boolean ):void {
			super.enabled = b;
			super.mouseEnabled = b;
			if( b ) {
				if( isOver ) {
					onOver();
				} else {
					onOut();
				}
			} else {
				gotoAndStop("inactive");
			}
		}
	}
}
